<template>
	<view class="mine">
		<g-navbar backgroundColor="#365fff" fontColor="#ffffff" :isShowBack="false" />
		<view class="user-info-container">
			<view class="user-info-left">
				<view class="user-avatar" @click="jump('/pages/user_center/userCenter')">
					<image :src="userInfo&&userInfo.avatars?userInfo.avatars:'/static/img/avatar.png'" mode="aspectFill"
						class="avatar" />
				</view>
				<view class="user-info-detail">
					<view class="user-name">
						{{userInfo?userInfo.nickname:'未登录'}}
					</view>
					<view class="user-phone">
						{{userInfo?userInfo.phone:'未登录'}}
					</view>
				</view>
			</view>
			<view class="user-info-right">
				<view class="user-identity" v-if="userInfo&&userInfo.identity" @click="onClickIdentity">
					{{userInfo?userInfo.identity:''}}
				</view>
			</view>
		</view>
		<view class="main-container">
			<view class="account-amount-container">
				<view class="account-amount-item">
					<view class="amount-count">
						<g-auto-zoom-text>￥{{userInfo?userInfo.balance:'0.00'}} </g-auto-zoom-text>
					</view>
					<view class="amount-label">
						基本余额(元)
					</view>
					<view class="withdraw-btn" @click="withdrawal(WITHDRAWAL_WAY.BASIC_BALANCE)">
						提现
					</view>
				</view>
				<view class="account-amount-item">
					<view class="amount-count">
						<g-auto-zoom-text>￥{{userInfo?userInfo.subsidy_balance:'0.00'}}</g-auto-zoom-text>
					</view>
					<view class="amount-label">
						扶持基金(元)
					</view>
					<view class="withdraw-btn" @click="withdrawal(WITHDRAWAL_WAY.SUPPORT)">
						提现
					</view>
				</view>
			</view>

			<!-- 		<view class="my-order">
				<text>查看我的订单</text>
				<i class="iconfont icon-arrow-right icon" />
			</view> -->

			<view class="entry-list-container">
				<template v-for="(item,index) in entryList" :key="index">
					<view class="entry-item" v-if="!item.isHide" @click="jump(item.path)">
						<view class="entry-item-left">
							<view class="left-icon">
								<i class="iconfont icon" :class="item.icon"></i>
							</view>
							<view class="entry-name">
								{{item.name}}
							</view>
						</view>
						<view class="arrow-icon">
							<i class="iconfont icon-arrow-right"></i>
						</view>
					</view>
				</template>
			</view>
		</view>
		<g-tabbar />
	</view>
</template>

<script lang="ts" setup>
	import { onShow, onLoad } from '@dcloudio/uni-app';
	import { useUserData } from '@/hooks/useUserData';
	import { useStore } from 'vuex';
	import { Ref, ref } from 'vue';
	import interceptor from '@/router/router.interceptor';
	import { WITHDRAWAL_WAY } from '@/enum/withdrawal';
	import { USER_LEVEL_TYPE, DIRECT_STATUS } from '@/enum/level';
	import { GET_STORE_USERINFO } from '@/store/gettersType';

	const store = useStore();


	const entryList = [
		// {
		// 	name: '公众号分享码',
		// 	icon: 'icon-cell-share',
		// 	path: '/pages/share/share',
		// },
		// {
		// 	name: '激活奖励查询',
		// 	icon: 'icon-cell-activate'
		// },
		// {
		// 	name: '交易分润',
		// 	icon: 'icon-cell-transaction'
		// },
		{
			name: '我的订单',
			icon: 'icon-order',
			path: '/pages_mall/my_order/myOrder'
		},
		{
			name: '分享展业',
			icon: 'icon-cell-share',
			path: '/pages_team/my_team/myTeam',
			// isHide: store.state.userInfo ? store.state.userInfo.customer_type < USER_LEVEL_TYPE.DIRECTOR : true,
		},
		{
			name: '我的团队',
			icon: 'icon-team',
			path: '/pages_team/member_list/memberList',
			isHide: store.state.userInfo ? store.state.userInfo.customer_type < USER_LEVEL_TYPE.DIRECTOR : true,
		},
		{
			name: '我的设备',
			icon: 'icon-cell-device',
			path: '/pages_device/my_device/myDevice'
		},
		{
			name: '我的结算卡',
			icon: 'icon-cell-card',
			path: '/pages_bind/card_pack/cardPack',
		},
		{
			name: '激活达标奖励',
			icon: 'icon-reward',
			path: '/pages_reward/reward_list/rewardList'
		},
		{
			name: '收货地址',
			icon: 'icon-location',
			path: '/pages_address/delivery_address/deliveryAddress'
		},
		// {
		// 	name: '投诉建议',
		// 	icon: 'icon-cell-suggest'
		// },
		{
			name: '抵扣金充值',
			icon: 'icon-cell-activate',
			path: '/pages_topup/topup_entry/topupEntry',
			isHide: store.state.userInfo ? store.state.userInfo.direct == DIRECT_STATUS.UNDIRECT : true,
		},
		{
			name: '设置',
			icon: 'icon-cell-setting',
			path: '/pages/user_center/userCenter',
		},
	];
	const jump = (path : string) : void => {
		console.log(store.state.userInfo.customer_type)
		if (path === '/pages_team/member_list/memberList' && store.state.userInfo && store.state.userInfo.customer_type < USER_LEVEL_TYPE.DIRECTOR) {
			uni.prompt.$showToast('当前账号无权限')
			return
		}
		uni.router.route(path)
	}



	const { getUserInfo } = useUserData();


	onLoad(() => {
		interceptor.beforeEach({ url: '/pages/mine/mine' })
	})

	onShow(async () => {
		await uni.loginManger.$interceptor;
		const userInfo = await getUserInfo(store.getters[GET_STORE_USERINFO].id);
		uni.store.local('userInfo', userInfo);
	})

	const withdrawal = (type : WITHDRAWAL_WAY) => {
		uni.router.route({
			url: '/pages_withdrawal/withdrawal_amount/withdrawalAmount',
			params: {
				type,
			}
		})
	}

	const count : Ref<number> = ref(0);

	let timer : number;

	const onClickIdentity = () => {
		clearTimeout(timer);
		count.value++;
		timer = setTimeout(() => {
			count.value = 0;
		}, 500)
		if (count.value >= 7) uni.router.route('/pages/test/test');
	}
</script>

<style scoped lang="scss">
	@import "./mine.scss";
</style>